package com.atguigu.ssyx.acl.service.Impl;


import com.atguigu.ssyx.acl.mapper.AdminMapper;
import com.atguigu.ssyx.acl.service.AdminService;
import com.atguigu.ssyx.model.acl.Admin;
import com.atguigu.ssyx.vo.acl.AdminQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public IPage selectPage(Page<Admin> pageParams, AdminQueryVo adminQueryVo) {
        LambdaQueryWrapper<Admin> wrapper = new LambdaQueryWrapper<>();
        if (
                StringUtils.isNotEmpty(adminQueryVo.getUsername())

        ) {
            wrapper.like(Admin::getUsername, adminQueryVo.getUsername());
        }
        if (
                StringUtils.isNotEmpty(adminQueryVo.getName())
        ) {
            wrapper.like(Admin::getName, adminQueryVo.getName());
        }

        IPage<Admin> pageModel = baseMapper.selectPage(pageParams, wrapper);

        return pageModel;
    }
}
